package net.ibizsys.eclipse.studio.data;

import java.util.ArrayList;
import java.util.List;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

/**
 * 
 * @author <a href='http://www.weibo.com/xjtoo' target='_blank'>Enmaai</a>
 */
public class IBizPub extends IBizData
{
	private JSONObject data;

	private String id;
	private String codename;
	private String pkgcodename;

	private List<Project> projs = new ArrayList<Project>();

	public IBizPub(JSONObject json)
	{
		init(json);
	}

	@Override
	public void init(JSONObject json)
	{
		this.data = json;

		this.codename = json.getString("codename");
		this.pkgcodename = json.getString("pkgcodename");
		this.id = json.getString("pssyssfpubid");

		JSONArray projArray = json.getJSONArray("prjs");

		if (projArray != null)
		{
			for (int i = 0; i < projArray.size(); i++)
			{
				JSONObject app = projArray.getJSONObject(i);

				projs.add(new Project(app,this.codename));
			}
		}
	}

	public String getCodename()
	{
		return codename;
	}

	public String getPkgcodename()
	{
		return pkgcodename;
	}

	public String getId()
	{
		return id;
	}

	public List<Project> getProjs()
	{
		return projs;
	}

	public Object getValue(String key)
	{
		if (data.containsKey(key))
		{
			return data.get(key);
		}
		return null;
	}

	@Override
	public String getText()
	{
		return getCodename();
	}
}
